<template>
  <div>
    <Head title="查询"></Head>
    <div class="search-container">
      <van-icon name="arrow-left" class="back" @click="back" />
      <van-search
        autofocus
        v-model="searchTxt"
        placeholder="请输入搜索关键词"
        @search="handleSearch"
      />
    </div>
    <QuestionList :list="searchResult" :showDesc="true" />
  </div>
</template>
<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import list from '@/assets/listData/index.js';
const searchTxt = ref('');
const searchResult = ref([]);
let allList = [];
list.map(items => {
  items.children.map(item => {
    if (item.data) {
      allList = allList.concat(item.data);
    }
  });
});
const handleSearch = () => {
  searchResult.value = allList.filter(item => {
    if (item.title.includes(searchTxt.value)) {
      return true;
    }
  });
};
const router = useRouter();
const back = () => {
  router.go(-1);
};
</script>
<style scoped lang="scss">
.search-container {
  .back {
    float: left;
    margin-top: 18px;
    margin-left: 10px;
  }
}
</style>
